package 代码记录.指定公司代码练习记录.备战快手;

/**
 * @author zx
 * @create 2023-05-13 12:05
 */
public class 最长公共前缀_14 {
    public String longestCommonPrefix(String[] strs) {
        if (strs.length == 0){
            return "";
        }
        String res = strs[0];
        for (int i = 1; i < strs.length; i++) {
            int j = 0;
            for (; j < res.length() && j < strs[i].length(); j++) {
                if (res.charAt(j) != strs[i].charAt(j))
                    break;
            }
            res = res.substring(0, j);
        }
        return res;
    }
}
